package com.demo.rxjavademo.ui;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;

import com.demo.rxjavademo.R;
import com.demo.rxjavademo.base.FullScreenActivity;
import com.demo.rxjavademo.http.Http;
import com.demo.rxjavademo.loader.FrescoImageLoader;
import com.demo.rxjavademo.mode.SplashInfo;
import com.facebook.drawee.view.SimpleDraweeView;

import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;

public class SplashActivity extends FullScreenActivity{
    private final String TAG = getClass().getSimpleName();
    private SimpleDraweeView mSplashView;
    private Context mContext = null;
    private FrescoImageLoader frescoImageLoader;
    Subscriber mSubscriber = new Subscriber<SplashInfo>() {
        @Override
        public void onSubscribe(Subscription s) {
            Log.e(TAG, "onSubscribe");
            s.request(Long.MAX_VALUE);
            //通常在这儿请求资源，参数就是要请求的数量

        }

        @Override
        public void onNext(SplashInfo splashInfo) {

            Log.e(TAG, "onNext");
            Log.d(TAG, splashInfo.getImg());
            Log.d(TAG, splashInfo.getText());
            frescoImageLoader.displayImage(mContext, splashInfo.getImg(), mSplashView);

        }


        @Override
        public void onError(Throwable t) {
            Log.e(TAG, "onError");

        }

        @Override
        public void onComplete() {
            Log.e(TAG, "onComplete");

        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        mSplashView= (SimpleDraweeView) findViewById(R.id.iv_splash);
        frescoImageLoader = new FrescoImageLoader();
        mContext = this;
        getSplash();
    }

    public void getSplash() {
        Http.getInstance().getSplash(mSubscriber, "1080*720");
    }
}
